package com.hotel.controller;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.hotel.annotation.ControllerEndpoint;
import com.hotel.entity.LoginLog;
import com.hotel.mapper.LoginLogMapper;
import com.hotel.response.Result;
import com.hotel.service.LoginLogService;
import com.hotel.vo.LoginLogVO;
import com.hotel.vo.UserVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 登入日志
 *
 * @Author xiaoge
 * @Date 2020/3/22 21:03
 * @Version 1.0
 **/
@Api(tags = "登入日志接口")
@RestController
@RequestMapping("/loginLog")
public class LoginLogController {


    @Resource
    private LoginLogService loginLogService;

    /**
     * 查询日志列表
     *
     * @return
     */
    @ApiOperation(value = "日志列表", notes = "登入日志列表，模糊查询")
    @GetMapping("/findLoginLogList")
    public Result findLoginLogList(@RequestParam(value = "username",required = false) String username,
                                   @RequestParam(value = "createTime",required = false)String createTime,
                                   @RequestParam(value = "endTime",required = false)String endTime,
                                   @RequestParam(value = "current", defaultValue = "1") Integer pageNum,
                                   @RequestParam(value = "size", defaultValue = "4") Integer pageSize
                                   ) {
        IPage<LoginLogVO> loginLogList = loginLogService.findLoginLogList(username,createTime,endTime,pageNum, pageSize);
        return Result.ok().data("login",loginLogList);
    }

    @ApiOperation(value = "删除登录日志")
    @RequiresPermissions({"login_log:delete"})
    @DeleteMapping("/deleteLogin/{id}")
    public Result deleteLogin(@PathVariable Integer id){
        int i = loginLogService.deleteLogin(id);
        return Result.ok().data("delete",i);
    }

    @ApiOperation(value = "批量删除登录日志")
    @RequiresPermissions({"login_log:batches"})
    @DeleteMapping("/deleteBatches")

    public Result deleteBatches(@RequestBody List<LoginLog> ids){
        System.err.println(ids);
        loginLogService.deleteBatches(ids);
        return Result.ok();
    }

    @ApiOperation(value = "清空登录日志")
    @RequiresPermissions({"login_log:clear"})
    @DeleteMapping("/clearLogin")
    public Result clearLogin(){
        loginLogService.clearLogin();
        return Result.ok();
    }

}
